// PROGRAMA : SCRP120A
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// IDENTIFICACAO CRIMINAL
// BIBLIOTECA : SISP
// CLIENTE : GEJUSPC - GERENCIA DE ESTADO DA JUSTICA, SEGURANCA
// PUBLICA E CIDADANIA / INSTITUTO DE IDENT.
// OBJETIVO : ALTERACAO DA FICHA DE INDICE CRIMINAL
// PROGRAMADOR: JOSE ANTONIO COELHO
// DATA : 29 DE JULHO DE 1997
// ALTERACAO
// ATUALIZACAO: FONETIZACAO DO NOME COMPLETO, NOME DO PAI, NOME
// DA MAE E ALCUNHAS NO ARQUIVO SIC-CADASTRO.
// POR : CARLOS HENRIQUE EM DATA: 18/11/1998
// POR : SOLON MIRANDA EM DATA: 18/02/1999
// POR : SOLON MIRANDA EM DATA: 19/08/1999
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm2000;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm2100;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm220a;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm2300;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp120cA;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp120cC;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp120cG;
import br.com.vti.sisp_sicrim.antigo.model.DidRg;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicNumero;
import br.com.vti.sisp_sicrim.antigo.model.SicSenha;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrp120c OBJETIVO : ALTERACAO DA FICHA DE INDICE CRIMINAL *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/scrp120c")
public class Scrp120c {
	// Views utilizadas
	SicCadastro criminalView = new SicCadastro();
	SicNumero numeroView = new SicNumero();
	SicSenha senhaView = new SicSenha();
	DidRg vwdidrg = new DidRg();
	// Telas/relatorios utilizados
	Scrm2000 scrm2000;
	Scrm2100 scrm2100;
	Scrm220a scrm220a;
	Scrm2300 scrm2300;
	Scrp120cA scrp120cA;
	Scrp120cC scrp120cC;
	Scrp120cG scrp120cG;
	// Includes utilizados
	Estla001 estla001 = new Estla001();
	// Areas globais / session
	Scrg001 scrg001;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	Scrp120a scrp120a;
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Scrp120c scrp120cAnterior;
	String faseproc = "0";

	// private String chave = "A";
	private String dmanas = "";
	private int jMax = 168;
	private long jUltNum = 0;
	private String jCrime = "";
	private int jInd1 = 0;
	private int jInd2 = 0;
	private String jDozeAster = "************";
	private int horax = 0;
	private int horat = 0;
	private int var = 0;
	// VARIAVEIS DA ESTATISTICA
	private String mod = "";
	private int vlt = 0;
	private String isn = "";
	private String[] tabm = { "", "   ", "VEI", "CON", "MUL", "   ", "IPV", "ROU", "   ", "   ", "   ", "   ", "   ", "IDC", "ICR", "FUN", "   ", "   " };

	private Scrm2000 preMapas() {
		scrm2000 = new Scrm2000(true, sessao);
		scrm2100 = new Scrm2100(true, sessao);
		scrm220a = new Scrm220a(true, sessao);
		scrm2300 = new Scrm2300(true, sessao);
		scrp120cA = new Scrp120cA(true, sessao);
		scrp120cC = new Scrp120cC(true, sessao);
		scrp120cG = new Scrp120cG(true, sessao);
		Arrays.fill(tabm, "");
		scrm2300.setDataCorrente(UtilBean.obtemDataDia());
		sessao.getScrg001().setWContadorw(0);

		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName());
		sessao.getScrg001().setWFuncaow("*** ALTERACAO ***");

		// Par�grafo: rp1()
		return scrm2000;
	}

	public Scrp120c(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar(Scrm2000 scrm2000, Scrm2100 scrm2100, Scrm220a scrm220a, Scrm2300 scrm2300, Scrp120cA scrp120cA, Scrp120cC scrp120cC, Scrp120cG scrp120cG) {
		try {
			main(scrm2000, scrm2100, scrm220a, scrm2300, scrp120cA, scrp120cC, scrp120cG);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Scrm2000 pscrm2000, Scrm2100 pscrm2100, Scrm220a pscrm220a, Scrm2300 pscrm2300, Scrp120cA pscrp120cA, Scrp120cC pscrp120cC, Scrp120cG pscrp120cG) throws Exception {
		if (pscrm2000 == null && pscrm2100 == null && pscrm220a == null && pscrm2300 == null && pscrp120cA == null && pscrp120cC == null && pscrp120cG == null) {
			primeiraVez = true;
			// scrm2000 = new Scrm2000 (primeiraVez);
			scrm2000 = preMapas();
			scrm2000.setNavegar("../scrp120c/executar");
			result.include("scrm2000", scrm2000);
			sessao.setAtributo("SCRP120C", this);
			scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pscrm2000, pscrm2100, pscrm220a, pscrm2300, pscrp120cA, pscrp120cC, pscrp120cG);
		}
		scrp120a = new Scrp120a(result, sessao);
		sessao.getScrg001().setWVltw(7);
		criminalView.wChv = "*";
		criminalView.wLoop += 1;
		scrp120cG.setJocorrencia(1);

		if (pscrm2000 != null) {
			scrm2000.receberTela(false, result);
		}
		// Par�grafo: fd33()
		criminalView.consultaRegEstadualGeral(scrm2000.getJregGeral());
		isn = criminalView.getId(); // *ISN(0880);
		// && S-MAOESQ = criminalView.wMAO-ESQUERDA)
		if (criminalView.registrosProcessados() > 0) {
			if (criminalView.getStatusReg() == 5) {
				scrm2000.enviarMensagem(null, "Esta ficha esta� excluida - Nao pode ser alterada");
				return;
			}

			criminalView.wData_nasc0 = String.valueOf(UtilBean.inverteData(criminalView.getDataNasc()));
			criminalView.wDataRegistro0 = UtilBean.inverteData(criminalView.getDataReg());

			scrm2100.setJpossuimandatopaberto(criminalView.getPossuiMandatoAberto());
			scrm220a.setJregGeral(criminalView.getRegEstadualGeral());
			scrm220a.setJidentidade(criminalView.getRegFederalCi());
			criminalView.wStatus0 = criminalView.getStatusReg();

			scrm220a.setJnomecompleto(criminalView.getNomeCompleto());
			scrm220a.setJpai(criminalView.getNomePai());
			scrm220a.setJmae(criminalView.getNomeMae());
			scrm2100.setDedos(1, 1, criminalView.getPolegarDireito());
			scrm2100.setDedos(2, 1, criminalView.getIndicadorDireito());
			scrm2100.setDedos(3, 1, criminalView.getMedioDireito());
			scrm2100.setDedos(4, 1, criminalView.getAnularDireito());
			scrm2100.setDedos(5, 1, criminalView.getMinimoDireito());
			scrm2100.setDedos(1, 2, criminalView.getPolegarEsquerdo());
			scrm2100.setDedos(2, 2, criminalView.getIndicadorEsquerdo());
			scrm2100.setDedos(3, 2, criminalView.getMedioEsquerdo());
			scrm2100.setDedos(4, 2, criminalView.getAnularEsquerdo());
			scrm2100.setDedos(5, 2, criminalView.getMinimoEsquerdo());
			scrm220a.setJdelegacia(criminalView.getNomeDelegacia());
			scrm220a.setJdescmunicipio(criminalView.getMunicipioRegGeral());
			scrm220a.setJmunicipio(criminalView.getCodigoMunicipioRegGeral());
			scrm220a.setJufreggeral(criminalView.getUfRegEstadualGeral());
			scrm220a.setJnoautos(criminalView.getNumeroAutos());
			scrm220a.setJdataatuacao(UtilBean.inverteDataDDMMYYYY(criminalView.getDataAtuacao()));
			scrm220a.setJnomeanterior(criminalView.getNomeAnterior());
			scrm220a.setJalcunha(criminalView.getApelidoAlcunhas());
			scrm220a.setJsexo(criminalView.getSexo());
			scrm220a.setJnaturalidade(criminalView.getNaturalidade());
			scrm220a.setJcodmunnascimento(criminalView.getCodigoMunicipioNasc());
			scrm220a.setJufnascimento(criminalView.getUfNaturalidade());
			scrm220a.setJdocapresentado(criminalView.getDocumentoApresent());
			scrm220a.setJnumdocapresentado(criminalView.getNumDocumentoApresent());
			scrm220a.setJorgaoexpuf(criminalView.getOrgaoExpUfUfUf());
			scrm220a.setJprofissao(criminalView.getProfissao());
			scrm220a.setJinstrucao(criminalView.getGrauInstrucao());
			scrm220a.setJavrua(criminalView.getAvRua());
			scrm220a.setJnumero(criminalView.getNumero());
			scrm220a.setJbairro(criminalView.getBairro());
			scrm220a.setJmunendereco(criminalView.getMunicipio());
			scrm220a.setJufendereco(criminalView.getEstado());
			scrm220a.setJcep(criminalView.getCep());
			scrm220a.setJcomplemento(criminalView.getComplemento());
			criminalView.wAltura0 = criminalView.getAltura();
			criminalView.wEstadoCivil0 = criminalView.getEstadoCivil();
			criminalView.wCutis0 = criminalView.getCodigoCutis();
			criminalView.wCorCabelo0 = criminalView.getCodigoCorCabelo();
			criminalView.wTipoCabelo0 = criminalView.getCodigoTipoCabelo();
			criminalView.wCorOlhos0 = criminalView.getCodigoCorOlhos();
			scrm2300.setJsinais(criminalView.getMarcaPartCicatTatuag());
			criminalView.wCompleicao0 = criminalView.getCompleicao();

			scrm2300.setJnomevitima(criminalView.getNomeVitima());
			scrm2300.setJmotivo(criminalView.getMotivoPrisaoLei());
			criminalView.wObservacoez = criminalView.getObservacao();

			scrm220a.setJcpf(criminalView.getCpf());
			scrp120cG.setJobservacoes(1, criminalView.wObservacoez[1]);
			scrp120cG.setJobservacoes(2, criminalView.wObservacoez[2]);
			scrp120cG.setJobservacoes(3, criminalView.wObservacoez[3]);
			scrp120cG.setJobservacoes(4, criminalView.wObservacoez[4]);
			verStatus();

			if (!scrm2100.getEnviada()) {
				result.include("scrm2100", scrm2100);
				sessao.setAtributo("SCRP120C", this);
				scrm2100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pscrm2100 != null) {
				scrm2100.receberTela(false, result);
			}

			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}

			scrm220a.setJdataNasc(dmanas);
			// Par�grafo: fd34()
			criminalView.consultaMaoDireitaMaoEsquerda(
			// jMaoDireita,
			scrm2100.getDedos(1, 1), scrm2100.getDedos(2, 1), scrm2100.getDedos(3, 1), scrm2100.getDedos(4, 1), scrm2100.getDedos(5, 1),
			// jMaoEsquerda
			scrm2100.getDedos(1, 2), scrm2100.getDedos(2, 2), scrm2100.getDedos(3, 2), scrm2100.getDedos(4, 2), scrm2100.getDedos(5, 2));
			if (criminalView.getRegEstadualGeral() != scrm2100.getJregGeral()) {
				if (jCrime.trim().equals("")) {
					jCrime = "*";
					scrm2100.enviarMensagem(null, "Formula Datil. Ja�Cadastrada Anteriormente.Consulte-a ou '-' Tecle <ENTER> p/ Cont.");
					return;
				}
			}
			if (criminalView.registrosProcessados() == 0) {
				// dao.rollback();
				scrm2100.enviarMensagem(null, "Ficha Criminal nao cadastrada");
				return;
			}

			if (!scrm220a.getEnviada()) {
				result.include("scrm220a", scrm220a);
				sessao.setAtributo("SCRP120C", this);
				scrm220a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pscrm220a != null) {
				scrm220a.receberTela(false, result);
			}

			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				result.include("scrm220a", scrm220a);
				sessao.setAtributo("SCRP120C", this);
				scrm220a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			scrm2300.receberTela(false, result);
			if (!scrm2300.getEnviada()) {
				result.include("scrm2300", scrm2300);
				sessao.setAtributo("SCRP120C", this);
				scrm2300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pscrm2300 != null) {
				scrm2300.receberTela(false, result);
			}

			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}

			criminalView.wData_atu = UtilBean.obtemDataCorrente();
			//

			criminalView.wHora = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 0, 2));
			criminalView.wMin = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 3, 2));
			criminalView.wSeg = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 6, 2));
			criminalView.wNse = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 9, 1));

			criminalView.wData_nasc0 = String.valueOf(criminalView.getDataNasc());
			criminalView.wDataRegistro0 = criminalView.getDataReg();

			criminalView.wData_nasc = UtilBean.subStr(criminalView.wData_nasc0, 4, 4) + UtilBean.subStr(criminalView.wData_nasc0, 2, 2) + UtilBean.subStr(criminalView.wData_nasc0, 0, 2);

			criminalView.wDataRegistro = (int) UtilBean.extraiDigitos(criminalView.wDataRegistro0, 8, 5, 4) * 10000 + (int) UtilBean.extraiDigitos(criminalView.wDataRegistro0, 8, 3, 2) * 100 + (int) UtilBean.extraiDigitos(criminalView.wDataRegistro0, 8, 1, 2);

			if (scrm2300.getJobservacoes(1).trim().equals("")) {
				if (criminalView.wChv.equals("*")) {
					criminalView.wChv = "";
					scrm2300.enviarMensagem(null, "Nenhuma ocorrencia foi informada.Se nao quiser '-' informar Tecle<ENTER>p/confirmar");
					return;
				}
			}
			gravaOcorrencias(pscrp120cG);
			if (scrm220a.getJmae().equals("*") || scrm220a.getJmae().trim().equals("")) {
				scrm220a.setJmae(jDozeAster);
			}
			if (scrm220a.getJpai().equals("*") || scrm220a.getJpai().trim().equals("")) {
				scrm220a.setJpai(jDozeAster);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm220a.getJalcunha(jInd1).trim().equals("") || scrm220a.getJalcunha(jInd1).equals("*")) {
					scrm220a.setJalcunha(jInd1, jDozeAster);
				}
			}
			if (scrm220a.getJnomeanterior().trim().equals("") || scrm220a.getJnomeanterior().equals("*")) {
				scrm220a.setJnomeanterior(jDozeAster);
			}
			if (scrm220a.getJnaturalidade().equals("*")) {
				scrm220a.setJnaturalidade(jDozeAster);
			}
			if (scrm220a.getJdocapresentado().equals("*")) {
				scrm220a.setJdocapresentado(jDozeAster);
			}
			if (scrm220a.getJavrua().equals("*")) {
				scrm220a.setJavrua(jDozeAster);
			}
			if (scrm220a.getJbairro().equals("*")) {
				scrm220a.setJbairro(jDozeAster);
			}
			if (scrm220a.getJcomplemento().trim().equals("") || scrm220a.getJcomplemento().equals("*")) {
				scrm220a.setJcomplemento(jDozeAster);
			}
			if (scrm2300.getJsinais().equals("*")) {
				scrm2300.setJsinais(jDozeAster);
			}
			if (scrm2300.getJnomevitima().equals("*")) {
				scrm2300.setJnomevitima(jDozeAster);
			}
			if (Integer.parseInt(scrm220a.getJdataatuacao()) < 1) {
				scrm220a.setJdataatuacao("0");
			}
			if (scrm220a.getJnoautos() < 1) {
				scrm220a.setJnoautos(0);
			}
			if (scrm220a.getJnumero() < 1) {
				scrm220a.setJnumero(0);
			}
			if (scrm220a.getJnumdocapresentado() < 1) {
				scrm220a.setJnumdocapresentado(0);
			}
			if (scrm220a.getJcodmunnascimento() < 1) {
				scrm220a.setJcodmunnascimento(0);
			}
			if (scrm220a.getJufnascimento().trim().equals("")) {
				scrm220a.setJufnascimento("**");
			}
			if (scrm220a.getJcep() < 1) {
				scrm220a.setJcep(0);
			}
			if (scrm220a.getJmunendereco() < 1) {
				scrm220a.setJmunendereco(0);
			}
			if (scrm220a.getJufendereco().trim().equals("")) {
				scrm220a.setJufendereco("**");
			}
			if (scrm220a.getJprofissao().equals("*") || scrm220a.getJprofissao().trim().equals("")) {
				scrm220a.setJprofissao(jDozeAster);
			}
			if (scrm220a.getJorgaoexpuf().equals("*") || scrm220a.getJorgaoexpuf().trim().equals("")) {
				scrm220a.setJorgaoexpuf(jDozeAster);
			}
			criminalView.setObservacao(criminalView.wObservacoez);
			criminalView.setPossuiMandatoAberto(scrm2100.getJpossuimandatopaberto());
			criminalView.setRegEstadualGeral(scrm220a.getJregGeral());
			criminalView.setRegFederalCi(scrm220a.getJidentidade());
			criminalView.setStatusReg(criminalView.wStatus0);
			criminalView.setTipoReg("AL");
			criminalView.setNomeCompleto(scrm220a.getJnomecompleto());
			criminalView.setNomePai(scrm220a.getJpai());
			criminalView.setNomeMae(scrm220a.getJmae());
			criminalView.setDataNasc(criminalView.wData_nasc00);
			criminalView.setPolegarDireito(scrm2100.getDedos(1, 1));
			criminalView.setIndicadorDireito(scrm2100.getDedos(2, 1));
			criminalView.setMedioDireito(scrm2100.getDedos(3, 1));
			criminalView.setAnularDireito(scrm2100.getDedos(4, 1));
			criminalView.setMinimoDireito(scrm2100.getDedos(5, 1));
			criminalView.setPolegarEsquerdo(scrm2100.getDedos(1, 2));
			criminalView.setIndicadorEsquerdo(scrm2100.getDedos(2, 2));
			criminalView.setMedioEsquerdo(scrm2100.getDedos(3, 2));
			criminalView.setAnularEsquerdo(scrm2100.getDedos(4, 2));
			criminalView.setMinimoEsquerdo(scrm2100.getDedos(5, 2));
			criminalView.setNomeDelegacia(scrm220a.getJdelegacia());
			criminalView.setMunicipioRegGeral(scrm220a.getJdescmunicipio());
			criminalView.setCodigoMunicipioRegGeral((int) scrm220a.getJmunicipio());
			criminalView.setUfRegEstadualGeral(scrm220a.getJufreggeral());
			criminalView.setDataReg(criminalView.wDataRegistro0);
			criminalView.setNumeroAutos(scrm220a.getJnoautos());
			criminalView.setDataAtuacao(Integer.parseInt(scrm220a.getJdataatuacao()));
			criminalView.setNomeAnterior(scrm220a.getJnomeanterior());
			criminalView.setApelidoAlcunhas(scrm220a.getJalcunha());
			criminalView.setSexo(scrm220a.getJsexo());
			criminalView.setNaturalidade(scrm220a.getJnaturalidade());
			criminalView.setCodigoMunicipioNasc((int) scrm220a.getJcodmunnascimento());
			criminalView.setUfNaturalidade(scrm220a.getJufnascimento());
			criminalView.setDocumentoApresent(scrm220a.getJdocapresentado());
			criminalView.setNumDocumentoApresent(scrm220a.getJnumdocapresentado());
			criminalView.setOrgaoExpUfUfUf(scrm220a.getJorgaoexpuf());
			criminalView.setProfissao(scrm220a.getJprofissao());
			criminalView.setGrauInstrucao(scrm220a.getJinstrucao());
			criminalView.setAvRua(scrm220a.getJavrua());
			criminalView.setNumero(scrm220a.getJnumero());
			criminalView.setBairro(scrm220a.getJbairro());
			criminalView.setMunicipio((int) scrm220a.getJmunendereco());
			criminalView.setEstado(scrm220a.getJufendereco());
			criminalView.setCep(scrm220a.getJcep());
			criminalView.setComplemento(scrm220a.getJcomplemento());
			criminalView.setAltura(criminalView.wAltura0);
			criminalView.setEstadoCivil(criminalView.wEstadoCivil0);
			criminalView.setCodigoCutis(criminalView.wCutis0);
			criminalView.setCodigoCorCabelo(criminalView.wCorCabelo0);
			criminalView.setCodigoTipoCabelo(criminalView.wTipoCabelo0);
			criminalView.setCodigoCorOlhos(criminalView.wCorOlhos0);
			criminalView.setMarcaPartCicatTatuag(scrm2300.getJsinais());
			criminalView.setCompleicao(criminalView.wCompleicao0);
			criminalView.setNomeVitima(scrm2300.getJnomevitima());
			criminalView.setMotivoPrisaoLei(scrm2300.getJmotivo());
			criminalView.setDataDocAtu(criminalView.wData_atu);
			criminalView.setHoraAtu(criminalView.wHora_atu);
			criminalView.setMatriculaFuncAtu(sessao.getScrg001().getWMatriculaw());
			criminalView.setCpf(scrm220a.getJcpf());
			funcoes.phonNome = scrm220a.getJnomecompleto();
			// Fonetizacao dos campos.
			// Phonet phonet = new Phonet ();
			funcoes.phonet(funcoes.phonArea);
			criminalView.setNomeCompletoPhon(funcoes.phonComb, 1, 168);
			if (scrm220a.getJmae() != jDozeAster) {
				// Phonet phonet = new Phonet ();
				funcoes.phonNome = scrm220a.getJmae();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomeMaePhon(funcoes.phonComb, 1, 155);
			}
			if (scrm220a.getJpai() != jDozeAster) {

				// Phonet phonet = new Phonet ();
				funcoes.phonNome = scrm220a.getJpai();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomePaiPhon(funcoes.phonComb, 1, 150);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm220a.getJalcunha(jInd1) != jDozeAster) {

					funcoes.phonNome = scrm220a.getJalcunha(jInd1);
					// Phonet phonet = new Phonet ();
					funcoes.phonet(funcoes.phonArea);
					jInd2 = jInd1 * 42;
					criminalView.setApelidoAlcunhasPhon(funcoes.phonComb, 1, 42);
				}
			}
			criminalView.atualiza();
			// ATUALIZA DID-RG REGISTROS PARA ABN
			vwdidrg.consultaNumeroRg(scrm220a.getJregGeral());

			vwdidrg.setNumeroRg(scrm220a.getJregGeral());
			vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
			vwdidrg.setHoraAtualizacao(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
			// abnFlag = "";
			vwdidrg.atualiza();
			// dao.commit();
			// dao.rollback();
			if (vwdidrg.registrosProcessados() == 0) {

				vwdidrg.setNumeroRg(scrm220a.getJregGeral());
				vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
				vwdidrg.setHoraAtualizacao(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
				// abnFlag = "";
				vwdidrg.grava();
				// dao.commit();
			}
			// ATUALIZA SIC-ESTATISTICAS NO CRIMINAL

			estla001.qde = 01;

			estla001.cpo = 02;

			sessao.getSisgsisp().setVlt(14);
			sessao.getSisgsisp().setVar(14);
			// ALTERA��O

			mod = tabm[14];

			estla001.esttip = 98;

			funcoes.estna001(estla001.cpo, estla001.esttip, estla001.qde, var, sessao.getScrg001().getWMatriculaw());
		}

		if (!scrp120cA.getEnviada()) {
			result.include("scrp120cA", scrp120cA);
			sessao.setAtributo("SCRP120C", this);
			scrp120cA.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (pscrp120cA != null) {
			scrp120cA.receberTela(false, result);
		}

		if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
			scrm2300.enviarMensagem(null, "Tecla invalida");
			return;
		}
		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			scrp120a.executar(null, null, null, null, null, null, null);
			return;
		}
		if (scrp120cA.getJconf().trim().equals("")) {
			scrm2300.enviarMensagem("jConf", "Confirme �S� ou �N�");
			return;
		}
		if (!(scrp120cA.getJconf().equals("S") || scrp120cA.getJconf().equals("N"))) {
			scrm2300.enviarMensagem("jConf", "Confirmacao invalida");
			return;
		}
		if (scrp120cA.getJconf().equals("N") || scrp120cA.getJconf().trim().equals("")) {
			// dao.rollback();
			scrp120a.executar(null, null, null, null, null, null, null);
			// return;
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {

				// dao.rollback();
				scrp120a.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE <ENTER>");
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}
		} else {
			if (criminalView.wLoop == 1) {

				if (!scrp120cC.getEnviada()) {
					result.include("scrp120cC", scrp120cC);
					sessao.setAtributo("SCRP120C", this);
					scrp120cC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (pscrp120cC != null) {
					scrp120cC.receberTela(false, result);
				}
				if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {

					// dao.rollback();
					scrp120a.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE <ENTER>");
					scrp120a.executar(null, null, null, null, null, null, null);
					return;
				}
				if (scrp120cC.getJmat() == 0) {
					scrp120cC.enviarMensagem("jMat", "INFORME A MATRICULA");
					result.include("scrp120cC", scrp120cC);
					sessao.setAtributo("SCRP120C", this);
					scrp120cC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (scrp120cC.getJmat() != sessao.getScrg001().getWMatriculaw()) {
					scrp120cC.enviarMensagem("jMat", "MATRICULA NAO CORRESPONDE A MATRICULA INICIAL");
					result.include("scrp120cC", scrp120cC);
					sessao.setAtributo("SCRP120C", this);
					scrp120cC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (scrp120cC.getJsenha().trim().equals("")) {
					scrp120cC.enviarMensagem("jSenha", "INFORME SUA SENHA");
					result.include("scrp120cC", scrp120cC);
					sessao.setAtributo("SCRP120C", this);
					scrp120cC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (scrp120cC.getJsenha() != sessao.getScrg001().getWSenhaw()) {
					scrp120cC.enviarMensagem("jSenha", "SENHA NAO CORRESPONDE A SENHA INICIAL");
					result.include("scrp120cC", scrp120cC);
					sessao.setAtributo("SCRP120C", this);
					scrp120cC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				senhaView.consultaMatricula(sessao.getScrg001().getWMatriculaw());

				senhaView.setMatAtualizador(sessao.getScrg001().getWMatriculaw());
				senhaView.atualiza();
				// dao.commit();
				criminalView.pesquisaPorId();
				criminalView.atualiza();
				// dao.commit();

				scrm2000.setMensagem("REGISTRO ALTERADO COM SUCESSO - TECLE <ENTER>");

				dmanas = "";
				for (int i1 = 1; i1 <= 5; i1++) {
					for (int i2 = 1; i2 <= 2; i1++) {
						criminalView.dedos[i1][i2] = "";
					}
				}
				jCrime = "";
			} else {
				senhaView.consultaMatricula(sessao.getScrg001().getWMatriculaw());

				senhaView.setMatAtualizador(sessao.getScrg001().getWMatriculaw());
				senhaView.atualiza();
				// dao.commit();
				criminalView.pesquisaPorId();
				criminalView.atualiza();
				// dao.commit();

				scrm2000.setMensagem("REGISTRO ALTERADO COM SUCESSO <BR> TECLE <ENTER>");
				dmanas = "";
				for (int i1 = 1; i1 <= 5; i1++) {
					for (int i2 = 1; i2 <= 2; i1++) {
						criminalView.dedos[i1][i2] = "";
					}
				}
				jCrime = "";
			}
		}
		// jVariaveis_da_tela = "";
		criminalView.wChave = "";
		criminalView.wText = "";
		jCrime = "";

		sessao.setAtributo("SCRP120C", this);
		result.include("scrm2000", scrm2000);
		scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
	}

	private void gravaOcorrencias(Scrp120cG pscrp120cG) {
		int ind = 0;

		criminalView.wI = 5;
		if (!scrp120cG.getJobservacoes(1).trim().equals("")) {
			if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
				scrm2300.enviarMensagem(null, "Tecla invalida");
				return;
			}
			criminalView.wObservacoez[1] = scrp120cG.getJobservacoes(1);
			criminalView.wObservacoez[2] = scrp120cG.getJobservacoes(1);
			criminalView.wObservacoez[3] = scrp120cG.getJobservacoes(1);
			criminalView.wObservacoez[4] = scrp120cG.getJobservacoes(1);
			for (ind = 2; ind <= 40; ind++) {
				scrp120cG.setJocorrencia(ind);
				if (scrp120cG.getJocorrencia() == 2) {
					criminalView.wJ = scrp120cG.getJocorrencia() + 4;
					criminalView.wL = scrp120cG.getJocorrencia() + 5;
					criminalView.wM = scrp120cG.getJocorrencia() + 6;
				} else {
					criminalView.wI = criminalView.wM + 1;
					criminalView.wJ = criminalView.wM + 2;
					criminalView.wL = criminalView.wM + 3;
					criminalView.wM = criminalView.wM + 4;
				}

				scrp120cG.setJobservacoes(1, criminalView.wObservacoez[criminalView.wI]);
				scrp120cG.setJobservacoes(2, criminalView.wObservacoez[criminalView.wJ]);
				scrp120cG.setJobservacoes(3, criminalView.wObservacoez[criminalView.wL]);
				scrp120cG.setJobservacoes(4, criminalView.wObservacoez[criminalView.wM]);

				if (!scrp120cG.getEnviada()) {
					result.include("scrp120cG", scrp120cG);
					sessao.setAtributo("SCRP120C", this);
					scrp120cG.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (pscrp120cG != null) {
					scrp120cG.receberTela(false, result);
				}
				//
				if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
					scrm2300.enviarMensagem(null, "TECLA INVALIDA");
					return;
				}

				if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
					scrp120a.executar(null, null, null, null, null, null, null);
					return;
				}
				// IF scrp120cG.getJobservacoes(1) = ' '
				// ESCAPE BOTTOM
				// END-IF
				criminalView.wObservacoez[criminalView.wI] = scrp120cG.getJobservacoes(1);
				criminalView.wObservacoez[criminalView.wJ] = scrp120cG.getJobservacoes(2);
				criminalView.wObservacoez[criminalView.wL] = scrp120cG.getJobservacoes(3);
				criminalView.wObservacoez[criminalView.wM] = scrp120cG.getJobservacoes(4);
			}
			// RESET scrp120cG.getJobservacoes(*)
			for (criminalView.wX = 4; criminalView.wX >= 2; criminalView.wX += -1) {
				if (!scrp120cG.getJobservacoes(criminalView.wX).trim().equals("")) {
					criminalView.wW = criminalView.wX - 1;
					for (criminalView.wY = criminalView.wW; criminalView.wY >= 1; criminalView.wY += -1) {
						if (scrp120cG.getJobservacoes(criminalView.wY).trim().equals("")) {
							scrm2300.enviarMensagem(null, "");
							return;
						}
					}
				}
				if (scrp120cG.getJobservacoes(1).trim().equals("")) {
					break;
				}
			}
		}
	}

	private void verStatus() {
		switch (criminalView.wStatus0) {
		case 0: {
			scrm220a.setJdescreg("Registro Normal");
			break;
		}
		case 1: {
			scrm220a.setJdescreg("Registro Cancelado");
			break;
		}
		case 2: {
			scrm220a.setJdescreg("Registro com Mandato de Prisao preventiva");
			break;
		}
		case 3: {
			scrm220a.setJdescreg("Condenado");
			break;
		}
		default: {
			break;
		}
		}
	}

	private void restaurarEstados(Scrm2000 pscrm2000, Scrm2100 pscrm2100, Scrm220a pscrm220a, Scrm2300 pscrm2300, Scrp120cA pscrp120cA, Scrp120cC pscrp120cC, Scrp120cG pscrp120cG) {
		this.scrp120cAnterior = (Scrp120c) sessao.getAtributo("SCRP120C");
		if (pscrm2000 != null) {
			scrm2000 = pscrm2000;
		} else {
			scrm2000 = this.scrp120cAnterior.scrm2000;
		}
		scrm2000.setSessao(sessao);
		if (pscrm2100 != null) {
			scrm2100 = pscrm2100;
		} else {
			scrm2100 = this.scrp120cAnterior.scrm2100;
		}
		scrm2100.setSessao(sessao);
		if (pscrm220a != null) {
			scrm220a = pscrm220a;
		} else {
			scrm220a = this.scrp120cAnterior.scrm220a;
		}
		scrm220a.setSessao(sessao);
		if (pscrm2300 != null) {
			scrm2300 = pscrm2300;
		} else {
			scrm2300 = this.scrp120cAnterior.scrm2300;
		}
		scrm2300.setSessao(sessao);
		if (pscrp120cA != null) {
			scrp120cA = pscrp120cA;
		} else {
			scrp120cA = this.scrp120cAnterior.scrp120cA;
		}
		scrp120cA.setSessao(sessao);
		if (pscrp120cC != null) {
			scrp120cC = pscrp120cC;
		} else {
			scrp120cC = this.scrp120cAnterior.scrp120cC;
		}
		scrp120cC.setSessao(sessao);
		if (pscrp120cG != null) {
			scrp120cG = pscrp120cG;
		} else {
			scrp120cG = this.scrp120cAnterior.scrp120cG;
		}
		scrp120cG.setSessao(sessao);
		this.faseproc = this.scrp120cAnterior.faseproc;
	}
}
